package com.itbooking.core.response;

import lombok.*;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ErrorResult {

    // 异常状态码
    private int status;
    // 用户看到的异常信息
    private String message;
    //异常堆栈信息
    private String exception;

    public static ErrorResult fail(ResponseCode responseCode, Throwable e, String message) {
        ErrorResult errorResult = ErrorResult.fail(responseCode, e);
        errorResult.setMessage(message);
        return errorResult;
    }

    public static ErrorResult fail(ResponseCode responseCode, Throwable e) {
        ErrorResult errorResult = new ErrorResult();
        errorResult.setStatus(responseCode.getCode());
        errorResult.setMessage(responseCode.getDesc());
        errorResult.setException(e.getMessage());
        return errorResult;

    }
}
